var util = {
    getUrlParams: function () {
        var url = window.location.search;

        //获取url参数显示查询条件
        var search = window.location.search;
        if(!search) return {}
        var parameterStr = search.split("?")[1];

        var parameterKV = parameterStr.split("&");
        var params = {};
        for (var z = 0; z < parameterKV.length; z++) {
            var kv = parameterKV[z].split("=");
            params[kv[0]] =  decodeURI(kv[1]);
        }
        return params;
    },
    getDataMatrix: function (config,params) {
        var url=config.url;
        var display=config.display;
        var summary=config.summary;
        var dataList = null;
        $.ajax({
            type: "POST",
            url: url,
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            async: false,
            data:params,
            success: function (data) {
                dataList = data;
                console.log(data)
            }
        });


        //深复制对象方法
        var cloneObj = function (obj) {
            var newObj = {};
            for (var key in obj) {
                newObj[key] = obj[key];
                if(summary.list[key]){
                    newObj[key] = obj[key];
                }else{
                    newObj[key] = null;
                }
            }
            newObj[summary.textField]=summary.text;
            console.log(newObj[summary.textField])
            return newObj;
        };

        if(summary&&dataList.length!=0){
            var flag=dataList[0][summary.field];
            var obj=null;
            var flagIndex=0;

            var resultList= []
            for(var index =0; index<dataList.length;index++){

                if(dataList[index][summary.field]!=flag){
                    obj=cloneObj(dataList[flagIndex])
                    for(var t=flagIndex+1 ; t<index;t++ ){

                        for(var name in dataList[0]){
                            if(summary.list[name]=="1"){
                                obj[name]+=dataList[t][name];
                            }else{
                                if(name!=summary.textField){
                                    obj[name]=null;
                                }

                            }
                        }
                    }
                    flag=dataList[index][summary.field];
                    flagIndex=index;

                    resultList.push(obj)
                }
                resultList.push(dataList[index])
            }
            dataList=resultList;
        }


        var dataMatrix = [];
        for (var i in dataList) {
            var arr = [];
            for (var z in display) {
                var val = dataList[i][display[z].value]
                /*if(util.CheckChinese(val)){
                    val="<p class='ch-con'>"+val+"</p>"
                }*/
                arr.push(val);
            }
            dataMatrix.push(arr);
        }
        var formData = {
            dataList: dataList,
            dataMatrix: dataMatrix
        }

        return formData
    },
    CheckChinese: function (val) {
        var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
        return reg.test(val);
    },
    CompareDate:function (time1, time2) {
    var time1Date = time1.stringToDate();
    var time2Date = time2.stringToDate();
    var bool = time1Date >= time2Date;
    return bool;
    },
    clone:function (obj) {

        var newObj = {}
        for(var name in obj){
            newObj[name]=obj[name];
        }
        return newObj;
    }
}


String.prototype.stringToDate = function () {

    var fullDate = this.split(" ")[0].split("-");


    return new Date(fullDate[0], fullDate[1] - 1, fullDate[2]);

}


//Vue.info=function(){
//
//}

var swi=true;

//swi 防止不停的点击，提示框不停的显示
function tips(tipContent,time){
    swi=false;
    var tip=$('<div class="tipsBox"><img src="../img/app/common/tip.png" /><span class="tip">'+tipContent+'</span></div>');
    tip.appendTo('body');
    setTimeout(function(){
        $('.tipsBox').remove();
        swi=true;
    },time)
};

function tipsTwo(content){
    var blur=$('<div class="blur"></div>');
    var tipTwo=$('<div class="tipTowBox"><img src="../img/storage/tuxiang.png" /><span>'+content+'</span><div class="closeTips">关闭</div></div>');
    blur.appendTo('body');
    tipTwo.appendTo('body');
}

/*$('.closeTips').live('click',function(){
    $('.blur').remove();
    $('.tipTowBox').remove();
})*/


